<template>
  <div class="maxBOx">
    <van-search v-model="searchVal" placeholder="请输入搜索关键词" />
    <div class="about">
      <div class="left">
        <article
          @click="changeClassify(item, index)"
          :class="{ active: activeFlag == index }"
          v-for="(item, index) in tapList"
          :key="index"
        >
          {{ item.val }}
        </article>
      </div>
      <div class="right">
        <div class="banner">
          <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
            <van-swipe-item>
              <img
                src="https://tse2-mm.cn.bing.net/th/id/OIP-C.rds3EDe-r6MhKp0HbjFFpwHaFj?w=240&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7"
                alt=""
              />
            </van-swipe-item>
            <van-swipe-item> </van-swipe-item>
          </van-swipe>
        </div>
        <div class="list">
          <div
            @click="$router.push('/goodsList')"
            class="card"
            v-for="(item, index) in classifList"
            :key="index"
          >
            <img :src="item.icon" alt="" />
            <p>{{ item.name }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getClassifyList } from "../network/request";
export default {
  data() {
    return {
      tapList: [
        {
          val: "所有分类",
          cid: "all",
        },
        {
          val: "居家",
          cid: "jujia2",
        },
        {
          val: "配件装饰",
          cid: "peishi2",
        },
        {
          val: "服饰",
          cid: "fuzhuang2",
        },
        {
          val: "电器",
          cid: "dianqi2",
        },
      ],
      searchVal: "",
      classifList: [],
      activeFlag: -1,
      localData: [], // 备份数据用分类
    };
  },
  mounted() {
    getClassifyList().then(({ data }) => {
      console.log(data.data);
      this.classifList = data.data;
      this.localData = data.data;
    });
  },
  methods: {
    changeClassify(val, index) {
      this.activeFlag = index;
      if (val.cid == "all") {
        this.classifList = this.localData;
      } else {
        this.classifList = this.localData.filter(
          (item) => item.type == val.cid
        );
      }
    },
  },
  components: {},
};
</script>

<style lang="scss">
.maxBOx {
  width: 100%;
  height: calc(100% - 100px);
  .list {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    .card {
      width: 30%;
      height: 140px;
      border: 1px solid #000;
      font-size: 12px;
      p {
        text-align: center;
        width: 100%;
        height: 20%;
        line-height: 25px;
      }
      img {
        width: 100%;
        height: 80%;
      }
    }
  }
  .about {
    display: flex;
    width: 100%;
    height: 100%;
    .left {
      width: 20vw;
      height: 100%;
      border-right: 1px solid #000;
      overflow: scroll;
    }
    .active {
      color: rgb(177, 66, 15);
      border-left: 3px solid #000;
    }
    .right {
      width: 80vw;
      height: 100%;
      overflow: scroll;
    }
    article {
      width: 100%;
      height: 40px;
      border: 1px solid #000;
      line-height: 40px;
      text-align: center;
    }
  }
}
</style>
